from flask import render_template, session

from . import home_blue
from models import db
from models.index import Commodity, User, Commodity_classify_three, Commodity_classify_one, Commodity_classify_two
from utils.index import if_user

# 主页
@home_blue.route('/')
def index():
    # 从自定义的方法中获取user
    user = if_user()
    # print('---------user--------', user)

    # 获取推荐值最高的六个产品
    commodity_recommend_top_6 = db.session.query(Commodity).order_by(-Commodity.recommend_num).limit(6)
    # print('--------reommend top 6----------', commodity_recommend_top_6.count())

    # 获取分类信息
    classify_one = db.session.query(Commodity_classify_one).all()

    return render_template('Home.html',
                           commodity_recommend_top_6=commodity_recommend_top_6,
                           classify_one=classify_one, user=user)
